# -*- coding: utf-8 -*-
from time import sleep

import allure
from common.page import Page
from regression_service_rdc.funtion.fun_main_rdc import MainRdc
from regression_service_rdc.page_elements.el_environment_rdc import environment_rdc


class EnvironmentListRdc(MainRdc):
    @allure.step('step:新增环境')
    def click_create_environment(self):
        Page.click(environment_rdc,'环境管理列表','新增')
        return CreateEnvironmentPageRdc()

    @allure.step('step:在环境名称搜索框输入环境名称搜索')
    def sendkeys_lookup_environment_name(self, environment_name):
        Page.send_key(environment_rdc, '环境管理列表', '环境名称搜索框', environment_name)
        sleep(1)
        return self

    @allure.step('step:删除搜索的环境')
    def delete_lookup_environment_name(self):
        Page.move_to_element(environment_rdc,'环境管理列表','查找环境名称')
        sleep(0.5)
        Page.click(environment_rdc,'环境管理列表', '删除第一个应用')
        sleep(0.5)
        Page.click(environment_rdc,'环境管理列表', '确认删除')
        sleep(5)
        return self

    @allure.step('step:断言删除成功')
    def assert_delete_lookup_environment_name(self):
        el_none = Page.element(environment_rdc,'环境管理列表', '查找环境名称')
        Page.assert_equal(None,el_none)
        return self


class CreateEnvironmentPageRdc:
    @allure.step('step:输入环境名称')
    def sendkeys_environment_name(self,environment_name):
        Page.send_key(environment_rdc,'新增环境页面','输入环境名称',environment_name)
        return self

    @allure.step('step:点击确定')
    def click_determine(self):
        Page.click(environment_rdc,'新增环境页面','确定')
        return EnvironmentListRdc()